package com.tencent.sr.iris.basic.saas.service.model.operate;

import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.OperateSecondBoardResponse;
import com.tencent.sr.iris.basic.saas.common.enums.IrisAuditStatusEnum;
import com.tencent.sr.iris.basic.saas.common.utils.CommonUtils;
import com.tencent.sr.iris.user.core.service.interfaces.enums.UserLevelEnum;
import io.swagger.annotations.ApiModel;
import java.util.Map;
import java.util.Optional;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@ApiModel(value = "运营平台-(邀新有礼)导出信息")
@Slf4j
@ColumnWidth(15)
public class OperateBoardInviteExportInfo {

    @ExcelProperty(value = "序号", index = 0)
    private int num;

    @ExcelProperty(value = "报名时间", index = 1)
    private String taskPhaseJoinTime;

    @ExcelProperty(value = "团长uid", index = 2)
    private String irisUid;

    @ExcelProperty(value = "unionId", index = 3)
    private String wechatUserUnionid;

    @ExcelProperty(value = "昵称", index = 4)
    private String wechatUserNickname;

    @ExcelProperty(value = "导师昵称", index = 5)
    private String advisorNickName;

    @ExcelProperty(value = "导师uid", index = 6)
    private String advisorUid;

    @ExcelProperty(value = "区域", index = 7)
    private String area;
    
    @ExcelProperty(value = "等级", index = 8)
    private String irisUidLevel;

    @ExcelProperty(value = "全部邀新人数", index = 9)
    private Integer totalInviteUserNum;

    @ExcelProperty(value = "有效邀新人数", index = 10)
    private Integer validInviteUserNum;

    @ExcelProperty(value = "实时进度", index = 11)
    private String bonusRuleStage;

    @ExcelProperty(value = "预估奖励金", index = 12)
    private Double predictAwardAmount;

    @ExcelProperty(value = "实际奖励金", index = 13)
    private Double awardAmount;

    /**
     * (0.待审核 1.未完成,2审核中,3.审批驳回,4.审核通过)
     */
    @ExcelProperty(value = "审核状态", index = 14)
    private String auditStatus;

    public void readFromSearchResponseData(OperateSecondBoardResponse response, Map<Long, String> orgMap) {
        this.setTaskPhaseJoinTime(response.getTaskPhaseJoinTime());
        this.setIrisUid(response.getIrisUid());
        this.setWechatUserUnionid(response.getWechatUserUnionid());
        this.setWechatUserNickname(response.getWechatUserNickname());

        String levelText = Optional.ofNullable(UserLevelEnum.getByValue(response.getIrisUidLevel()))
                .map(UserLevelEnum::getDesc).orElse(StrUtil.EMPTY);
        this.setIrisUidLevel(levelText);
        
        this.setArea(orgMap.getOrDefault(response.getAreaId(), ""));
        
        this.setTotalInviteUserNum(response.getTotalInviteUserNum());
        this.setValidInviteUserNum(response.getValidInviteUserNum());
        this.setBonusRuleStage("进行至" + response.getBonusRuleStage() + "阶段");
        this.setPredictAwardAmount(CommonUtils.longToDouble(response.getPredictAwardAmount()));
        this.setAwardAmount(CommonUtils.longToDouble(response.getAwardAmount()));
        this.setAuditStatus(IrisAuditStatusEnum.getByStatus(response.getAuditStatus()));
        this.setAdvisorNickName(response.getAdvisorNickName());
        this.setAdvisorUid(response.getAdvisorUid());
    }

}
